<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
       
        function user(name,age){
            let data={name:name,age:age};//对象
            Object.defineProperties(this,{  //将上面对象的属性的封装
                name:{
                        set (value){
                            data.name=value;
                        },
                        get (){
                            return data.name;
                        }
            },
              age:{
                        set (value){
                            data.age=value;
                        },
                        get (){
                            return data.age;
                        }
            }
            });
        }
        let user1=new user("唐玮",22);
        user1.age=25;
        console.log(user1.name);
        console.log(user1.age);
       
    </script>
</body>
</html>